//1.导入 Vue 和 VueRouter 的包
import Vue from "vue"
import VueRouter from "vue-router"
import Layout from "@/views/layout/index.vue"
import Login from "@/views/login/index.vue"
import Home from "@/views/home/Home.vue"

//2.调用Vue.use()函数，把VueRouter 安装为Vue的插件
// Vue.use() 函数的作用，就是来安装插件的
Vue.use(VueRouter)

const routes = [
  {
    path: "/",
    component: Layout,
    children: [
      {
        path: "/",
        name: "home",
        component: Home,
      },
      {
        path: "/product",
        name: "product",
        component: () => import("@/views/product/index.vue"),
        children: [
          {
            path: "list",
            name: "productlist",
            component: () => import("@/views/product/list/index.vue"),
          },
          {
            path: "category",
            name: "category",
            component: () => import("@/views/product/category/index.vue"),
          },
          {
            path: "productpage",
            name: "productpage",
            component: () => import("@/views/product/list/ProductPage.vue"),
            meta:{
              activeMenu:'/product/list'
            }
          },
        ],
      },
      {
        path: "/order",
        name: "order",
        component: () => import("@/views/order/index.vue"),
        children: [
          {
            path: "list",
            name: "orderlist",
            component: () => import("@/views/order/list/index.vue"),
          },
          {
            path: "collect",
            name: "collect",
            component: () => import("@/views/order/collect/index.vue"),
          },
        ],
      },
      {
        path: "/advert",
        name: "advert",
        component: () => import("@/views/advert/index.vue"),
        children: [
          {
            path: "list",
            name: "list",
            component: () => import("@/views/advert/list/index.vue"),
          },
        ],
      },
    ],
  },
  {
    path: "/login",
    name: "login",
    component: Login,
  },
]

//3.创建路由的实例对象
const router = new VueRouter({
  routes,
})

//4.向外共享路由的实例对象
export default router
